#!/usr/bin/perl


# Linux CPU and Memory
#             total       used       free     shared    buffers     cached
#Mem:        500472     459300      41172          0     131104     157476
#-/+ buffers/cache:     170720     329752
#Swap:            0          0          0

#cat /proc/stat
#cpu  6314920 27721 2039492 1184983360 2360843 4550 92023 0 0
#       user  nice   system   idle      iowait irq  softirq
#cpu0 6314920 27721 2039492 1184983360 2360843 4550 92023 0 0
#intr 1730492045 184 7 0 0 0 0 0 0 0 0 0 0 104 0 0 0 0 0 0 0 0 0 0 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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0 0 0 0 0 0 0 0 0 0 0 0 8701729 667533 10608228 436
#ctxt 3628056442
#btime 1479994382
#processes 743964
#procs_running 1
#procs_blocked 0
#softirq 1113713278 0 541561557 4905362 4983191 0 0 10958793 0 1969113 549335262
#
#   第一行的数值表示的是CPU总的使用情况，所以我们只要用第一行的数字计算就可以了。下表解析第一行各数值的含义： 解析（单位：jiffies）
# (jiffies是内核中的一个全局变量，用来记录自系统启动一来产生的节拍数，在linux中，一个节拍大致可理解为操作系统进程调度的最小时间片，不同linux内核可能值有不同，通常在1ms到10ms之间)
# user (6314920)    从系统启动开始累计到当前时刻，处于用户态的运行时间，不包含 nice值为负进程。
# nice (27721)      从系统启动开始累计到当前时刻，nice值为负的进程所占用的CPU时间
# system (2039492)  从系统启动开始累计到当前时刻，处于核心态的运行时间
# idle (1184983360)   从系统启动开始累计到当前时刻，除IO等待时间以外的其它等待时间iowait (12256) 从系统启动开始累计到当前时刻，IO等待时间(since 2.5.41)
# irq (2360843)       从系统启动开始累计到当前时刻，硬中断时间(since 2.6.0-test4)
# softirq (4550)   从系统启动开始累计到当前时刻，软中断时间(since 2.6.0-test4)
# 结论2：CPU时间=user+system+nice+idle+iowait+irq+softirq


# 1. 返回物理内存，2，返回交换分区， 3， 空，4，空，5，CPU使用率。
$cpu=1113713278+int(rand(100));
print "Memory=459300/500472,Swap=0/0,,,+$cpu\n";